from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import pymysql

app = Flask(__name__)
# 设置连接数据库的URL
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@127.0.0.1:3306/db_16'
# 数据库和模型类同步修改
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# 查询时会显示原始SQL语句
app.config['SQLALCHEMY_ECHO'] = True

# 用SQLAlchemy包装一下
db = SQLAlchemy(app)


# 类型
class Type(db.Model):
    # 表名
    __tablename__ = 'tbl_types'

    # 数据库真正存在的字段
    id = db.Column(db.Integer, primary_key=True)  # 主键
    name = db.Column(db.String(32), unique=True)  # 名字


@app.route("/index")
def index():
    result = Type.query.all()
    for res in result:
        print(res.name)
    return "11111"


if __name__ == '__main__':
    app.run()
